﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EPPLib.Managers;
using EPPLib.Messages;

namespace EPPWebMVC.Controllers
{
    public class SystemController : BaseController
    {
        [Authorize]
        public ActionResult Logout()
        {
            Service.Logout(CurrentTargetUrl, new LogoutMessage());
            Service.ClearSession();
            SetBaseViewData();
            return View();
        }

        [Authorize]
        public ActionResult Hello()
        {
            HelloResponseMessage responseMessage = Service.Hello(CurrentTargetUrl, new HelloMessage());
            SetBaseViewData(responseMessage);
            return View();
        }

        [Authorize]
        public ActionResult ChangePassword()
        {
            SetBaseViewData();
            return View();
        }
        [Authorize]
        [HttpPost]
        public ActionResult ChangePassword(FormCollection data)
        {
            LoginMessage message = new LoginMessage();
            message.RegistrarID = CurrentAccount;
            message.Password = CurrentPassword;
            message.NewPassword = data["newPasswordBox"];
            LoginResponseMessage responseMessage = Service.Login(CurrentTargetUrl, message);
            if (responseMessage.Response.Status == EPPLib.Objects.ResponseObject.ResponseStatus.Done)
                Data.SaveConfigurationNewPassword(CurrentUserID, message.NewPassword);
            SetBaseViewData(responseMessage);
            return View();
        }

    }
}
